package com.tiantian.app.manager;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONObject;

import android.content.Context;
import android.os.Handler;
import android.provider.Settings.Secure;

import com.infindo.frame.data.DataProcessor;
import com.infindo.frame.data.mo.MoliscMessage;
import com.infindo.frame.data.mo.ServiceMessage;
import com.infindo.frame.data.net.CallbackListener;
import com.infindo.frame.util.JSONUtil;
 
 
public class HttpManager {

  
    public static void requestGet(Context context,MoliscMessage message,String type,CallbackListener listener){
        try {
            JSONObject jsonObj = message.wrapObject();
			String jsonStr = jsonObj.toString();
			DataProcessor.getInstance().reqProcData(context,Const.getRequestServerUrl(),jsonStr, type, listener);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
     }
    
    public static void requestWeather(Context context,int position,String type,CallbackListener listener){
        try {
 
			DataProcessor.getInstance().reqGet(context,"http://m.weather.com.cn/data/101190401.html", type , listener);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
     }
    
    public static void reqestImage(Context context,String imgUrl,int position,String type,CallbackListener listener){
    	  DataProcessor.getInstance().imageProc(context, Const.getImageUrl()+imgUrl, "jpeg", type, listener, position);
    }
    
 
    public static void requestPost(Context context,MoliscMessage message,String serMethod, String type,CallbackListener listener){
	        try {
		        ServiceMessage serviceMessage = new ServiceMessage();
//		        serviceMessage.setClazz("serviceMessage");
		        serviceMessage.setUid(""+DataModel.DeviceID);
		        serviceMessage.setPlatform(""+DataModel.Platform);
		        serviceMessage.setVersionId(""+DataModel.VersionID);
		        serviceMessage.setAppId(""+DataModel.AppID);
		        serviceMessage.setSerMethod(""+serMethod);
 
		        if (message != null ) {
		            List parameters = new ArrayList();
		            parameters.add(JSONUtil.wrapObject(message));
		            serviceMessage.setParameters(parameters);
		        }
				String jsonStr = JSONUtil.serviceMessageToJSONStringer(serviceMessage);
				DataProcessor.getInstance().reqProcData(context,Const.getRequestServerUrl(),jsonStr, type, listener);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	}
	
	
	public static void requestUpload(MoliscMessage message,String serviceName,String methodName,byte[] data,byte[] thamnailData,int position,String type,Handler handler,CallbackListener listener){
	    try {
	        ServiceMessage serviceMessage = new ServiceMessage();
	        serviceMessage.setPlatform("ANDROID");
	        serviceMessage.setVersionId("1");
	        serviceMessage.setClazz("ServiceMessage");
	
	//        if (DataModel.getSessionId() != null) {
	//            serviceMessage.setSessionId(DataModel.getSessionId());
	//        }
	        
	        
	        if (message != null ) {
	            List parameters = new ArrayList();
	//            JSONObject jsonObj = message.toJSONObject();
	//            parameters.add(jsonObj);
	            parameters.add(JSONUtil.wrapObject(message));
	            serviceMessage.setParameters(parameters);
	        }
			String jsonStr = JSONUtil.serviceMessageToJSONStringer(serviceMessage);
//			DataProcessor.getInstance().reqUpload2(Const.getBinaryUrl(), jsonStr, data,thamnailData, position,type, true, handler, listener);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
